import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 日历定义
 * @date: 2018-9-26
 * @version: 1.0.0


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, isTenantRoleLevel } from 'utils/utils';
var prefix = "".concat(CPAAS_PLATFORM, "/v1"); // 日历层级判断

function calendarsApi(params) {
  return isTenantRoleLevel() ? "".concat(params.tenantId, "/calendars") : "calendars";
}
/**
 * 平台级日历查询
 * @async
 * @function searchCalendar
 * @param {object} params - 查询条件
 * @param {?string} params.calendarName - 描述
 * @param {?string} params.countryId - 国际/地区编码
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */


export function searchCalendar(_x) {
  return _searchCalendar.apply(this, arguments);
}
/**
 *  获取日历明细
 * @async
 * @function searchCalendarDetail
 * @param {object} params - 查询条件
 * @param {!string} params.calendarId - 日历ID
 * @returns {object} fetch Promise
 */

function _searchCalendar() {
  _searchCalendar = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params)), {
              method: 'GET',
              query: _objectSpread({}, param)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _searchCalendar.apply(this, arguments);
}

export function searchCalendarDetail(_x2) {
  return _searchCalendarDetail.apply(this, arguments);
}
/**
 * 平台级日历保存
 * @async
 * @function addCalendar
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

function _searchCalendarDetail() {
  _searchCalendarDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _searchCalendarDetail.apply(this, arguments);
}

export function addCalendar(_x3) {
  return _addCalendar.apply(this, arguments);
}
/**
 * 平台级日历更新
 * @async
 * @function updateCalendar
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

function _addCalendar() {
  _addCalendar = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params)), {
              method: 'POST',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _addCalendar.apply(this, arguments);
}

export function updateCalendar(_x4) {
  return _updateCalendar.apply(this, arguments);
}
/**
 *  获取工作日
 * @async
 * @function searchWeekdays
 * @param {object} params - 查询条件
 * @param {!string} params.calendarId - 日历ID
 * @returns {object} fetch Promise
 * /v1/calendars/{calendarId}/calendar-holidays
 */

function _updateCalendar() {
  _updateCalendar = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params)), {
              method: 'PUT',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateCalendar.apply(this, arguments);
}

export function searchWeekdays(_x5) {
  return _searchWeekdays.apply(this, arguments);
}
/**
 * 更新工作日信息
 * @async
 * @function updateWeekday
 * @param {object} params - 查询条件
 * @param {!number} params.calendarId - 日历ID
 * @param {!array<object>} params.data - 工作日数据
 * @returns {object} fetch Promise
 */

function _searchWeekdays() {
  _searchWeekdays = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId, "/calendar-weekdays"), {
              method: 'GET',
              query: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _searchWeekdays.apply(this, arguments);
}

export function updateWeekday(_x6) {
  return _updateWeekday.apply(this, arguments);
}
/**
 *  获取公共假期
 * @async
 * @function searchHolidays
 * @param {object} params - 查询条件
 * @param {!string} params.calendarId - 日历ID
 * @returns {object} fetch Promise
 */

function _updateWeekday() {
  _updateWeekday = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId, "/calendar-weekdays/set-weekday"), {
              method: 'POST',
              body: _toConsumableArray(params.data)
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _updateWeekday.apply(this, arguments);
}

export function searchHolidays(_x7) {
  return _searchHolidays.apply(this, arguments);
}
/**
 * 更新公休假期
 * @async
 * @function updateHoliday
 * @param {object} params - 查询条件
 * @param {!number} params.calendarId - 租户ID
 * @param {!object} params.data - 公休假期对象
 * @returns {object} fetch Promise
 */

function _searchHolidays() {
  _searchHolidays = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            param = parseParameters(params);
            return _context7.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(param.calendarId, "/calendar-holidays"), {
              method: 'GET',
              query: _objectSpread({}, param)
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _searchHolidays.apply(this, arguments);
}

export function updateHoliday(_x8) {
  return _updateHoliday.apply(this, arguments);
}
/**
 * 平台级日历更新
 * @async
 * @function addHoliday
 * @param {object} params - 查询条件
 * @param {!number} params.calendarId - 租户ID
 * @param {!object} params.data - 公休假期对象
 * @returns {object} fetch Promise
 */

function _updateHoliday() {
  _updateHoliday = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId, "/calendar-holidays"), {
              method: 'PUT',
              body: _objectSpread({}, params.data)
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updateHoliday.apply(this, arguments);
}

export function addHoliday(_x9) {
  return _addHoliday.apply(this, arguments);
}
/**
 * 批量移除公休假期
 * @async
 * @function deleteHoliday
 * @param {object} params - 查询条件
 * @param {!number} params.calendarId - 租户ID
 * @param {!array<object>} params.data - 公休假期对象列表
 * @returns {object} fetch Promise
 */

function _addHoliday() {
  _addHoliday = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId, "/calendar-holidays"), {
              method: 'POST',
              body: _objectSpread({}, params.data)
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _addHoliday.apply(this, arguments);
}

export function deleteHoliday(_x10) {
  return _deleteHoliday.apply(this, arguments);
}

function _deleteHoliday() {
  _deleteHoliday = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(prefix, "/").concat(calendarsApi(params), "/").concat(params.calendarId, "/calendar-holidays/batch-delete"), {
              method: 'POST',
              body: _toConsumableArray(params.data)
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _deleteHoliday.apply(this, arguments);
}